// 修复后的键盘测试
const KeyboardController = require('./src/KeyboardController');

async function testKeyboard() {
  console.log('========================================');
  console.log('修复后的键盘测试');
  console.log('========================================\n');

  const keyboard = new KeyboardController();

  // 测试1: 检查PowerPoint是否运行
  console.log('测试1: 检查PowerPoint是否运行');
  const isRunning = await keyboard.isPowerPointRunning();
  console.log(`PowerPoint运行状态: ${isRunning ? '运行中' : '未运行'}`);
  
  if (!isRunning) {
    console.log('\n⚠️ PowerPoint未运行，无法测试键盘控制');
    console.log('请打开PowerPoint和一个演示文稿，然后重新运行此测试');
    return;
  }

  // 测试2: 尝试激活PowerPoint窗口
  console.log('\n测试2: 尝试激活PowerPoint窗口');
  const focused = await keyboard.focusPowerPoint();
  console.log(`窗口激活结果: ${focused ? '成功' : '失败'}`);

  // 测试3: 发送按键
  console.log('\n测试3: 发送按键测试');
  console.log('等待3秒，请确保PowerPoint在前台...');
  await sleep(3000);

  console.log('发送右箭头键（下一页）...');
  const result1 = await keyboard.sendKey('right');
  console.log(`发送结果: ${result1 ? '成功' : '失败'}`);

  await sleep(2000);

  console.log('发送左箭头键（上一页）...');
  const result2 = await keyboard.sendKey('left');
  console.log(`发送结果: ${result2 ? '成功' : '失败'}`);

  console.log('\n========================================');
  if (result1 && result2) {
    console.log('✅ 键盘控制测试通过！');
  } else {
    console.log('❌ 键盘控制测试失败');
  }
  console.log('========================================');
}

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

testKeyboard().catch(error => {
  console.error('测试过程中发生错误:', error);
  process.exit(1);
});